﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Hi_Baidu.Packet.InPacket
{
    class GetPostFriendInfo_ReplyPacket : BaseInPackage
    {
        public GetPostFriendInfo_ReplyPacket(InPackage inpackage) : base(inpackage)
        {
        }

        public override void InitPackage()
        {
            int Offset = 0;
            //昵称长度
            byte[] NickNameLength = new byte[4];
            Array.ConstrainedCopy(this.Body["HEAD"], Offset, NickNameLength, 0, 4);
            Offset += 4;
            //昵称
            byte[] NickName = new byte[BitConverter.ToInt32(NickNameLength, 0)];
            Array.ConstrainedCopy(this.Body["HEAD"], Offset, NickName, 0, NickName.Length);
            Offset += NickName.Length;
            //用户名长度
            byte[] UsernameLength = new byte[4];
            Array.ConstrainedCopy(this.Body["HEAD"], Offset, UsernameLength, 0, 4);
            Offset += 4;
            //用户名
            byte[] Username = new byte[BitConverter.ToInt32(UsernameLength, 0)];
            Array.ConstrainedCopy(this.Body["HEAD"], Offset, Username, 0, Username.Length);
            Offset += Username.Length;
            //备注长度
            byte[] MarkLength = new byte[4];
            Array.ConstrainedCopy(this.Body["HEAD"], Offset, MarkLength, 0, 4);
            Offset += 4;
            //备注
            byte[] Mark = new byte[BitConverter.ToInt32(MarkLength, 0)];
            Array.ConstrainedCopy(this.Body["HEAD"], Offset, Mark, 0, Mark.Length);
            Offset += Mark.Length;
            //个性签名长度
            byte[] ProdLength = new byte[4];
            Array.ConstrainedCopy(this.Body["HEAD"], Offset, ProdLength, 0, 4);
            Offset += 4;
            //个性签名
            byte[] Prod = new byte[BitConverter.ToInt32(ProdLength, 0)];
            Array.ConstrainedCopy(this.Body["HEAD"], Offset, Prod, 0, Prod.Length);
            Offset += Prod.Length;
            //真实姓名长度
            byte[] NameLength = new byte[4];
            Array.ConstrainedCopy(this.Body["HEAD"], Offset, NameLength, 0, 4);
            Offset += 4;
            //真实姓名
            byte[] Name = new byte[BitConverter.ToInt32(NameLength, 0)];
            Array.ConstrainedCopy(this.Body["HEAD"], Offset, Name, 0, Name.Length);
            Offset += Name.Length;
            //性别
            byte[] Sex = new byte[4];
            Array.ConstrainedCopy(this.Body["HEAD"], Offset, Sex, 0, 4);
            Offset += 4;
            //年龄
            byte[] Age = new byte[4];
            Array.ConstrainedCopy(this.Body["HEAD"], Offset, Age, 0, 4);
            Offset += 4;
            //电话长度
            byte[] TelLength = new byte[4];
            Array.ConstrainedCopy(this.Body["HEAD"], Offset, TelLength, 0, 4);
            Offset += 4;
            //电话
            byte[] Tel = new byte[BitConverter.ToInt32(TelLength, 0)];
            Array.ConstrainedCopy(this.Body["HEAD"], Offset, Tel, 0, Tel.Length);
            Offset += Tel.Length;
            //EMAIL长度
            byte[] EmailLength = new byte[4];
            Array.ConstrainedCopy(this.Body["HEAD"], Offset, EmailLength, 0, 4);
            Offset += 4;
            //EMAIL
            byte[] Email = new byte[BitConverter.ToInt32(EmailLength, 0)];
            Array.ConstrainedCopy(this.Body["HEAD"], Offset, Email, 0, Email.Length);
            Offset += Email.Length;
            //大纲长度
            byte[] SynopsisLength = new byte[4];
            Array.ConstrainedCopy(this.Body["HEAD"], Offset, SynopsisLength, 0, 4);
            Offset += 4;
            //大纲
            byte[] Synopsis = new byte[BitConverter.ToInt32(SynopsisLength, 0)];
            Array.ConstrainedCopy(this.Body["HEAD"], Offset, Synopsis, 0, Synopsis.Length);
            Offset += Synopsis.Length;
            //头像名称长度
            byte[] HeadImageLength = new byte[4];
            Array.ConstrainedCopy(this.Body["HEAD"], Offset, HeadImageLength, 0, 4);
            Offset += 4;
            //头像名称
            byte[] HeadImage = new byte[BitConverter.ToInt32(HeadImageLength, 0)];
            Array.ConstrainedCopy(this.Body["HEAD"], Offset, HeadImage, 0, HeadImage.Length);
            Offset += HeadImage.Length;
            //最后一次上线时间长度
            byte[] LastOnlineTimeLength = new byte[4];
            Array.ConstrainedCopy(this.Body["HEAD"], Offset, LastOnlineTimeLength, 0, 4);
            Offset += 4;
            //最后一次上线时间
            byte[] LastOnlineTime = new byte[BitConverter.ToInt32(LastOnlineTimeLength, 0)];
            Array.ConstrainedCopy(this.Body["HEAD"], Offset, LastOnlineTime, 0, LastOnlineTime.Length);
            Offset += LastOnlineTime.Length;
            //最后一次下线时间长度
            byte[] LastOfflineTimeLength = new byte[4];
            Array.ConstrainedCopy(this.Body["HEAD"], Offset, LastOfflineTimeLength, 0, 4);
            Offset += 4;
            //最后一次下线时间
            byte[] LastOfflineTime = new byte[BitConverter.ToInt32(LastOfflineTimeLength, 0)];
            Array.ConstrainedCopy(this.Body["HEAD"], Offset, LastOfflineTime, 0, LastOfflineTime.Length);
            Offset += LastOfflineTime.Length;
            //用户ID
            byte[] UserId = new byte[4];
            Array.ConstrainedCopy(this.Body["HEAD"], Offset, UserId, 0, 4);
            Offset += 4;
            //权限
            byte[] Mession = new byte[4];
            Array.ConstrainedCopy(this.Body["HEAD"], Offset, Mession, 0, 4);
            Offset += 4;
            //本身用户名长度
            byte[] UsernamesLength = new byte[4];
            Array.ConstrainedCopy(this.Body["HEAD"], Offset, UsernamesLength, 0, 4);
            Offset += 4;
            //本身用户名
            byte[] Usernames = new byte[BitConverter.ToInt32(UsernamesLength, 0)];
            Array.ConstrainedCopy(this.Body["HEAD"], Offset, Usernames, 0, Usernames.Length);
            Offset += Usernames.Length;

            this.DIC_CONTENT.Add("NICKNAME", NickName);
            this.DIC_CONTENT.Add("USERNAME", Username);
            this.DIC_CONTENT.Add("MARK", Mark);
            this.DIC_CONTENT.Add("PROD", Prod);
            this.DIC_CONTENT.Add("NAME", Name);
            this.DIC_CONTENT.Add("SEX", Sex);
            this.DIC_CONTENT.Add("AGE", Age);
            this.DIC_CONTENT.Add("TEL", Tel);
            this.DIC_CONTENT.Add("EMAL", Email);
            this.DIC_CONTENT.Add("SYNOPSIS", Synopsis);
            this.DIC_CONTENT.Add("HEADIMAGE", HeadImage);
            this.DIC_CONTENT.Add("LASTONLINETIME", LastOnlineTime);
            this.DIC_CONTENT.Add("LASTOFFLINETIME", LastOfflineTime);
            this.DIC_CONTENT.Add("USERID", UserId);
            this.DIC_CONTENT.Add("MESSION", Mession);
            this.DIC_CONTENT.Add("USERNAMES", Usernames);
        }

        /// <summary>
        ///     获得指定KEY的值
        /// </summary>
        public String GetValueByKey(String Key)
        {
            try
            {
                if (Key == "ONLINESTATE")
                {
                    return BitConverter.ToBoolean(this.DIC_CONTENT[Key], 0).ToString();
                }
                if (Key != "SEX" && Key != "AGE" && Key != "USERID" && Key != "MESSION" && Key != "LOGINLIVE")
                {
                    return Encoding.Default.GetString(this.DIC_CONTENT[Key]);
                }
                else
                {
                    return BitConverter.ToInt32(this.DIC_CONTENT[Key], 0).ToString();
                }
            }
            catch (Exception ex)
            {
                return null;
            }
        }
    }
}
